<template>
	<view class="cent">
		<view style="width: 100%;margin-top: 10px;display: flex;align-items: center;justify-content: space-around;">
			<input type="number" placeholder="请输入要查询的司机手机号" v-model="phone"/>
			<button @click="searchdriver">查询</button>
		</view>
		<view style="display: flex;align-items: center;flex-direction: column;" v-if="search==1">
			<image src="../../static/img/pic_fangdajin.png" mode="" style="width: 181px;height: 121px;margin-top: 49px;margin-left: 46px;"></image>
			<text style="color: #000000;font-size: 18px;font-weight: 500;">暂无查询结果</text>
			<text style="color: #777777;font-size: 15px;margin-top: 12px;">请您输入司机手机号~</text>
		</view>
		<view class="cap" v-if="search==2" >
			<text style="color: #042A58;font-size: 32rpx;margin-left: 30rpx;">{{list.username}}</text>
			<text style="color:#627995;font-size: 32rpx;margin-left: 15px;">{{list.phone}}</text>
			<text style="color:#FF5F2E;font-size: 12px;margin-left: 70px;width:92px;height:40px;background:rgba(255,248,242,1);border-radius:8px;display: flex;align-items: center;justify-content: center;" @click="carts">添加我的车队</text>
		</view>
		<view style="display: flex;align-items: center;flex-direction: column;" v-if="search==3">
			<image src="../../static/img/pic_fangdajin.png" mode="" style="width: 181px;height: 121px;margin-top: 49px;margin-left: 46px;"></image>
			<text style="color: #000000;font-size: 18px;font-weight: 500;">暂无查询结果</text>
			<text style="color: #777777;font-size: 15px;margin-top: 12px;">请您输入正确的司机手机号~</text>
		</view>
	</view>
</template>

<script>
	import {ajax} from "../../apis.js"
	import {ajaxs} from "../../captainapi.js"
	export default {
		data() {
			return {
				search:1,
				phone:"",
				list:[],
			}
		},
		methods: {
			searchdriver(){
				var that=this
				ajax({
					url:"/v1/manager/select/driver",
					method:"post",
					data:{
						account:this.phone
					},
					success(res){
						that.list=res.data.message
						if(res.data.message==null){
							that.search=3
						}else{
							that.search=2
							that.list=res.data.message
						}
					}
				})
			},
			carts(){
				ajaxs({
					url:"/v1/manager/bind/driver",
				method:"post",
				data:{
					id:this.list.id
				},
				success(res){
					if(res.data.status=="OK"){
						uni.showToast({
						    title: '添加司机成功',
							icon:"none"
						})
						setTimeout(function(){
										uni.navigateBack({
											delta:1
										})
									},2000)
					}else{
						uni.showToast({
						    title: res.data.message,
							icon:"none"
						})
					}
				}
				})
				
			}
		}
	}
</script>

<style>
	page{
		height: 100%;
	}
	.cap{
		width:355px;
		height:60px;
		background:rgba(255,255,255,1);
		border-radius:8px;
		margin-top: 10px;
		display: flex;
		align-items: center;
	}
input{
	width:261px;
	height:50px;
	background:rgba(255,255,255,1);
	border-radius:8px;
	color: #9B9B9B;
	background-image: url(../../static/img/icon_sousuo.png);
	background-size: 20px 20px;
	background-repeat: no-repeat;
	padding-left: 40px;
	background-position: 12px   16px;
	margin-left: 15px;
	box-sizing: border-box;
}
button{
	width:84px;
	height:50px;
	background:rgba(4,42,88,1);
	border-radius:8px;
	color: #FFFFFF;
}
</style>
